//
//  sendconfig.m
//  tcpoctest
//
//  Created by gump on 5/16/13.
//  Copyright (c) 2013 gump. All rights reserved.
//

#import "sendconfig.h"
#import "bigHeadImageDataSource.h"

@implementation sendconfig

-(void)SendConfigP:(NSString *)mail
            withPS:(NSString *)ps
          withName:(NSString *)name
           withSex:(char)sex
           withAge:(char)age
      withProvince:(char)province
          withCity:(char)city
           withUID:(NSString*)uid
{
    //发送:主索引10char(1)，副索引10char(1)，
    //用户名长度char(1),用户名char(X),密码char(32),
    //昵称长度char(1),昵称char(X),性别char(1)1男2女,
    //年龄char(1)0-255岁,省char(1),市char(1)设备UDID长度char(1),
    //设备UDIDchar(x),小头像长度int,小头像char(X),
    //大头像长度int,大头像char(x),渠道ID长度char(1),渠道IDchar(x)
    
    
    if ([self CheckLogin]) {
        return;
    }
    
    NSData *imageData = UIImageJPEGRepresentation([DataControl shareControl].iImage, JPG_COMPRESS_RATE);
    
    if ([DataControl shareControl].bigHIDS.UserBigImage == nil) {
        return;
    }
    
    NSData *bigimagedata = UIImageJPEGRepresentation([DataControl shareControl].bigHIDS.UserBigImage, JPG_COMPRESS_RATE);
    int bigimagelength = [bigimagedata length];
    int imagelength = [imageData length];
    
    const char *namechar = [name UTF8String];
    
    NSString *strver = T_CHANNEL;
    
    int l = NAME_PL * 1 + CHAR_PL * 9 + [mail length] +
    strlen(namechar) + INT_PL + imagelength + INT_PL * 2 +
    CHAR_PL + [uid length] + bigimagelength + [strver length];
    
    [self initDataByLength:l];
    
    [sb WriteChar:[mail length]];
    [sb WriteString:mail withLength:[mail length]];
    
    [sb WriteString:ps withLength:NAME_PL];
    
    [sb WriteChar:strlen(namechar)];
    [sb WriteString:name withLength:strlen(namechar)];
    
    [sb WriteChar:sex];
    [sb WriteChar:age];
    [sb WriteChar:province];
    [sb WriteChar:city];
    
    [sb WriteChar:[uid length]];
    [sb WriteString:uid withLength:[uid length]];
    
    [sb WriteInt:imagelength withNTT:NTT_SMALL2BIG];
    [sb WriteData:(char *)[imageData bytes] withLength:imagelength];
    
    [sb WriteInt:bigimagelength withNTT:NTT_SMALL2BIG];
    [sb WriteData:(char *)[bigimagedata bytes] withLength:bigimagelength];
    
    [sb WriteChar:[strver length]];
    [sb WriteString:strver withLength:[strver length]];
    
    [self Package];
}

@end
